
var _nullFun = function _null() {};
//公共弹窗方法
function alertBox(text,confirmFun, cancelFun) {
    var _confirmBox = $('#pop');
    confirmFun = confirmFun || _nullFun;
    cancelFun = cancelFun || closeBox;
    var $confirmY = $('#pop .yes');
    var $confirmN = $('#pop .no');
    var _confirmfun = confirmFun;
    var _cancelfun = cancelFun;
    _confirmBox.fadeIn();
    $('.pop-text').text(text)
    $('.mask').fadeIn();
    $confirmY.on('click', function () {
        _confirmBox.fadeOut();
        $('.mask').fadeOut();
        $confirmN.unbind();
        $confirmY.unbind();
        _confirmfun();
    });
    $confirmN.on('click', function() {
        _confirmBox.fadeOut();
        $('.mask').fadeOut();
        $confirmY.unbind();
        $confirmN.unbind();
        _cancelfun();
    });
};
/*关闭弹窗*/
function closeBox() {
    $('#pop').fadeOut();
    $('.mask').fadeOut();
}


$(function () {
    if($(window).width() < 768){
        $('html').css('font-size', $(window).width()/15);
    }
    var header=$('.header'); //得到导航对象
    $('.menu-img').click(function () {
        header.addClass('cur');
    })
    $('.close').click(function () {
        header.removeClass('cur');
    })
});
var home={
    index:function () {
        var header=$('.header'); //得到导航对象
        var win=$(window); //得到窗口对象
        var sc=$(document);//得到document文档对象。
        header.addClass('active')
        win.scroll(function() {
            if(sc.scrollTop()>=75){
                header.removeClass('active').css('backgroundColor','#fff');
            }else{
                header.addClass('active').css('backgroundColor','transparent');
            }
        });
        var num = 0;
        if ($(window).width() >= 1349) {
            num = 6;
        } else {
            num = 4;
        }

        var swiper_home = new Swiper('.home-swiper', {
            pagination:  '.swiper-pagination',
            paginationClickable: true,
            loop:true ,
            autoplay:'4000',
        });
        var product_swiper = new Swiper('.product-swiper', {
            slidesPerView: num ,
            prevButton:'.swiper-button-prev',
            nextButton:'.swiper-button-next',
        });
        $('.product-swiper-box').on('click','.swiper-slide',function () {
            var type = $(this).attr('data-type');
            $('.btn-box-a').attr('href', $('.btn-box-a').attr('data-href') + '/' + type);
            $(this).addClass('active').siblings().removeClass('active');
            $('.products-list').eq($(this).index()).addClass('active').siblings().removeClass('active');
        })
    }
}
var about={
    index:function () {
        var num = 0;
        if ( $(window).width() >= 1024) {
            num = 3;
        }else{
            num = 1
        }

        var product_swiper = new Swiper('.about-swiper', {
            slidesPerView:num,
            slidesPerGroup:1,
            pagination : '.swiper-pagination',
            paginationType : 'fraction',
            prevButton:'.swiper-button-prev',
            nextButton:'.swiper-button-next',
        });

    }
}
var contact={
    index:function () {
        var chected = true;
        $('.submit').click(function () {
            if (chected == true) {
                chected = false;
                check();
                function check() {
                    var name = $('#name').val();//姓名
                    var email = $('#email').val(); //邮箱
                    var phone = $('#phone').val(); //手机号
                    var company = $('#company').val(); //公司
                    var message = $('#message').val(); //公司
                    if(name==''){
                        alertBox('Username can not be empty');
                        return false;
                    }
                    if(email==''){
                        alertBox('E-mail can not be empty');
                        return false;
                    }else if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email)){
                        alertBox('E-mail format is incorrect');
                        return false;
                    }
                    if(phone==''){
                        alertBox('Phone number can not be blank');
                        return false;
                    }
                    if(company==''){
                        alertBox('Company name can not be empty');
                        return false;
                    }
                    if(message==''){
                        alertBox('Message can not be empty');
                        return false;
                    }
                    $.post('/api/contactForm', {name : name, email : email, phone : phone, company : company, message : message}, function (data) {
                        switch (data.errcode) {
                            case 0 :
                                chected = true;
                                alert('Message success');
                                break;
                            default :
                                chected = true;
                                alert(data.errmsg);
                                break;
                        }
                    }, 'json');
                }
            }
        })
    }
}
var contactCn={
    index:function () {
        var chected = true;
        $('.submit').click(function () {
            if (chected == true) {
                chected = false;
                check();
                function check() {
                    var name = $('#name').val();//姓名
                    var email = $('#email').val(); //邮箱
                    var phone = $('#phone').val(); //手机号
                    var company = $('#company').val(); //公司
                    var message = $('#message').val(); //公司
                    if(name==''){
                        alertBox('用户名不能为空');
                        return false;
                    }
                    if(email==''){
                        alertBox('电子邮件不能为空');
                        return false;
                    }else if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email)){
                        alertBox('电子邮件格式不正确');
                        return false;
                    }
                    if(phone==''){
                        alertBox('电话号码不能空白');
                        return false;
                    }
                    if(company==''){
                        alertBox('公司名称不能为空');
                        return false;
                    }
                    if(message==''){
                        alertBox('消息不能为空');
                        return false;
                    }
                    $.post('/api/contactForm', {name : name, email : email, phone : phone, company : company, message : message}, function (data) {
                        switch (data.errcode) {
                            case 0 :
                                chected = true;
                                alert('提交成功');
                                break;
                            default :
                                chected = true;
                                alert(data.errmsg);
                                break;
                        }
                    }, 'json');
                }
            }
        })
    }
}
var products={
    index:function () {
        var num = 0;
        var num2 = 0;
        var space = 0;
        if ($(window).width() >= 1346) {
            num = 6;
        } else{
            num = 4;
        }
        if ($(window).width() >= 1004) {
            num2 = 4;
            space = 20
        } else{
            num2 = 1;
            space = 0
        }
        var product_swiper = new Swiper('.product-swiper', {
            slidesPerView: num ,
            prevButton:'.product-swiper .swiper-button-prev',
            nextButton:'.product-swiper .swiper-button-next',
        });
        $('.product-swiper-box').on('click','.swiper-slide',function () {
            $(this).addClass('active').siblings().removeClass('active');
        })

        var galleryThumbs = new Swiper('.swiper-detail', {
            spaceBetween: space,
            slidesPerView: num2,
            nextButton: '.left .swiper-button-next',
            prevButton: '.left .swiper-button-prev',

        });
        $(document).on('click','.swiper-detail .swiper-slide',function () {
            // console.log($(this).index())
            $(this).addClass('active').siblings().removeClass('active');
            var src = $(this).find('img').attr('src');
            $('.img-show img').attr('src',src)
        })
        $('.tab-list a').click(function () {
            $(this).addClass('active').siblings().removeClass('active');
            $('.data-box .data-detail').eq($(this).index()).addClass('active').siblings().removeClass('active');
        })
        $('.icon-icon').click(function () {
            var src = $(this).parent().find('img').attr('src');
            $('#img-big').attr('src',src);
            $('#img-warper').fadeIn();
            $('.mask2').fadeIn();
        })
        $('.close,.mask2').click(function () {
            $('#img-warper').fadeOut();
            $('#mask2').fadeOut();
        })
    },

}

